package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针;

import java.util.HashMap;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/17 10:40
 */
public class 数位和相等数对的最大和 {
    //https://leetcode.cn/problems/minimum-deletions-to-make-array-divisible/
    public int maximumSum(int[] nums) {
        int res = -1;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int sum = get(nums[i]);
            int j = map.getOrDefault(sum, -1);
            if (j == -1 || nums[i] > nums[j])
                map.put(sum, i);
            if (j != -1) {
                res = Math.max(res, nums[i] + nums[j]);
            }
        }
        return res;
    }

    int get(int x) {
        int res = 0;
        while (x != 0) {
            res += x % 10;
            x /= 10;
        }
        return res;
    }
}
